﻿using System;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Linq.Expressions;

namespace AuchanScan.Datas
{
    public class TrophyBase : INotifyPropertyChanged
    {
        public int _Id;
        public int Id 
        {
            get { return _Id; }
            set
            {
                if (_Id != value)
                {
                    _Id = value;
                    RaisePropertyChanged(() => Id);
                }
            }
        }

        public string Name { get; set; }
        public string Description { get; set; }
        public bool HasBeenWon { get; set; }
        public DateTime GotDate { get; set; }
        [XmlIgnore]
        public string Image
        {
            get { return string.Format("../images/trophe{0}.png", Id); }
        }


        #region INotifyPropertyChanged Implementation

        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        protected void RaisePropertyChanged<T>(Expression<Func<T>> expression)
        {
            if (!(expression.Body is MemberExpression))
                return;

            MemberExpression memberExpression = (MemberExpression)expression.Body;
            string propertyName = memberExpression.Member.Name;
            RaisePropertyChanged(propertyName);
        }
        
        #endregion
    }
}